<?php

class Social_Post_Category extends Social_Base
{
    public function init()
    {
        $this->setTableName('post_categories');
        $this->setPrimaryKey('category_id');
    }

    public function checkUser($categoryId, $userId)
    {
        $category = $this->getByPrimary($categoryId);
        if(empty($category)) {
            throw new InvalidArgumentException('Category not found with id: ' . $categoryId);
        }

        if($category['user_id'] != $userId) {
            throw new InvalidArgumentException('You have no permission to save your post in this category');
        }
        return true;
    }

    public function checkGroup($categoryId, $groupId)
    {
        $category = $this->getByPrimary($categoryId);
        if(empty($category)) {
            throw new InvalidArgumentException('Category not found with id: ' . $categoryId);
        }

        if($category['group_id'] != $groupId) {
            throw new InvalidArgumentException('You have no permission to save your post in this category');
        }
        return true;
    }
}
